package org.springblade.modules.device.controller;

import com.alibaba.fastjson.JSON;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.tool.api.R;
import org.springblade.modules.device.dto.DeviceAlertDto;
import org.springblade.modules.device.dto.DeviceInfoSaveDto;
import org.springblade.modules.device.service.IDeviceAlertService;
import org.springblade.modules.device.service.IDeviceInfoService;
import org.springblade.modules.device.vo.DeviceAlertStatusVo;
import org.springblade.modules.device.vo.DeviceDetailVo;
import org.springblade.modules.device.vo.DeviceRunStatusVo;
import org.springblade.modules.system.entity.Region;
import org.springblade.modules.system.vo.RegionVO;
import org.springblade.modules.system.wrapper.RegionWrapper;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@AllArgsConstructor
@RequestMapping("/device")
@Api(value = "软件升级-设备app版本表", tags = "设备app版本表接口")
@Slf4j
public class DeviceInfoController {

	@Resource
	private IDeviceInfoService deviceInfoService;
	@Resource
	private IDeviceAlertService deviceAlertService;

	/**
	 * 详情
	 */
	@PostMapping("/submit")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "传入设备信息", notes = "传入设备信息")
	public R<Boolean> submit(@RequestBody DeviceInfoSaveDto deviceInfoSaveDto) {
		Boolean a = deviceInfoService.submitDeviceInfo(deviceInfoSaveDto);
		return R.data(a);
	}


	/**
	 * 详情
	 */
	@GetMapping("/getDeviceInfo")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "传入设备信息", notes = "传入设备信息")
	public R<Object> getDeviceInfo(String deviceNo,String salesOrderNo) {
		return R.data(deviceInfoService.getDeviceInfo(deviceNo,salesOrderNo));
	}

	/**
	 * 详情
	 */
	@GetMapping("/getSaleOrders")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "传入设备信息", notes = "传入设备信息")
	public R<Object> getSaleOrders() {
		return R.data(deviceInfoService.getSaleOrders());
	}


	/**
	 * 详情
	 */
	@GetMapping("/alert2")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "传入设备信息", notes = "传入设备信息")
	public R<Object> alert2(String content,String toMail,String deviceNo) {
		return R.data(deviceInfoService.alert2(content,toMail,deviceNo));
	}


	/**
	 * 详情
	 */
	@PostMapping("/alert")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "传入设备信息", notes = "传入设备信息")
	public R<Object> alert(@RequestBody DeviceAlertDto deviceAlertDto) {
		log.info("deviceAlert{}",JSON.toJSONString(deviceAlertDto));
		Boolean i = deviceInfoService.sendAlert(deviceAlertDto);
		return R.data(i);
	}



	/**
	 * 详情
	 */
	@PostMapping("/statusEvent")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "传入设备信息", notes = "传入设备信息")
	public R<Object> statusEvent(@RequestBody Map<String,Object> map) {
		log.info("deviceStatusEvent{}",JSON.toJSONString(map));
		return R.data(1);
	}

	/**
	 * 详情
	 */
	@PostMapping("/statusEvent2")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "传入设备信息", notes = "传入设备信息")
	public R<Object> statusEvent2(@RequestBody List<Map<String,Object>> content) {
		log.info("deviceStatusEvent2{}",content.size());
		return R.data(1);
	}

	/**
	 * 详情
	 */
	@GetMapping("/getDeviceAlert")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "传入设备信息", notes = "传入设备信息")
	public R<Object> getDeviceAlert(String alertType) {
		List<?> deviceAlert = deviceAlertService.getDeviceAlert(alertType);
		return R.data(deviceAlert);
	}


	/**
	 * 详情
	 */
	@GetMapping("/allDevices")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "传入设备信息", notes = "传入设备信息")
	public R<List<DeviceDetailVo>> allDevices() {
		List<DeviceDetailVo> deviceDetailVos = deviceAlertService.allDevices();
		return R.data(deviceDetailVos);
	}
}
